# Python Qt4 bindings for GUI objects
from PyQt4 import QtGui
# import the Qt4Agg FigureCanvas object, that binds Figure to 
# Qt4Agg backend. It also inherits from QWidget 
from matplotlib.backends.backend_qt4agg \
import FigureCanvasQTAgg as FigureCanvas
# Matplotlib Figure object 
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg \
import NavigationToolbar2QT as NavigationToolbar
# attempt to replace matplotlib with vispy
# 
#import vispy.mpl_plot as plt

class MplCanvas(FigureCanvas): 
	"""Class to represent the FigureCanvas widget""" 
	def __init__(self):
		# setup Matplotlib Figure and Axis 
		self.fig = Figure() 
		self.ax = self.fig.add_subplot(111)
		# initialization of the canvas 
		FigureCanvas.__init__(self, self.fig) 
		# we define the widget as expandable 
		FigureCanvas.setSizePolicy(self,
		QtGui.QSizePolicy.Expanding,
		QtGui.QSizePolicy.Expanding) 
		# notify the system of updated policy
		FigureCanvas.updateGeometry(self)


class MplWidget(QtGui.QWidget): 
	"""Widget defined in Qt Designer""" 
	def __init__(self, parent = None):
		# initialization of Qt MainWindow widget 
		QtGui.QWidget.__init__(self, parent) 
		# set the canvas to the Matplotlib widget 
		self.canvas = MplCanvas()
		# create a vertical box layout 
		self.vbl = QtGui.QVBoxLayout() 
		# add mpl widget to vertical box 
		self.vbl.addWidget(self.canvas) 
		# set the layout to th vertical box 
		self.setLayout(self.vbl)
		self.main_frame = QtGui.QWidget()
		self.mpl_toolbar = NavigationToolbar(self.canvas, self.main_frame)
		self.vbl.addWidget(self.mpl_toolbar)
